package com.daniu101.productbargan.service.impl;


import com.daniu101.productbargan.service.IProductService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@Service
public class ProductServiceImpl implements IProductService {


    @Override
    public String uploadCover(MultipartFile cover) {

        //        long size = cover.getSize();
//        System.out.println(size);

        // formData 的 key的值
        String coverName = cover.getName();

        //原来的文件名
        String coverOriginalFilename = cover.getOriginalFilename();

        // 相对路径 转 绝对路径
        //D:\localpath
        File dest = new File("D:\\localpath\\" + UUID.randomUUID().toString() + coverOriginalFilename);

        try {
            cover.transferTo(dest);
            return "1";
        } catch (IOException e) {

        }

        return "-2";

    }
}
